package mo.leetcode_top;

public class L7 {

    public int reverse(int x) {
        long res = 0;
        while (x != 0) {
            int num = x % 10;
            x = x / 10;
            /**
             * 0在中间的情况没有考虑
             */
            if (num != 0 || res != 0) {
                res = res * 10 + num;
            }
        }
        /**
         * 小于int最小值需要考虑
         */
        if (res > Integer.MAX_VALUE || res < Integer.MIN_VALUE) {
            return 0;
        }
        return (int) res;
    }

    public static void main(String[] args) {
        L7 test = new L7();
        System.out.println(test.reverse(-2147483648));
    }
}
